<!-- 排班管理 -->
<template>
  <div class="dashboard-container transport-task customer-list-box">
    <div class="app-container">
      <!-- 搜索框 -->
      <el-card class="search-card-box" shadow="never">
        <el-form label-width="80px">
          <el-row :gutter="60">
            <el-col :span="8">
              <el-form-item label="员工账号">
                <el-input v-model="listQuery.employeeNumber" placeholder="请输入员工账号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="员工姓名">
                <el-input v-model="listQuery.name" placeholder="请输入员工姓名" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="工作模式">
                <el-input v-model="listQuery.workPatternName" placeholder="请输入工作模式" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="60">
            <el-col :span="8">
              <el-form-item label="月份">
                <el-date-picker
                  v-model="listQuery.month"
                  type="month"
                  placeholder="请选择月份"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所属机构">
                <el-input v-model="listQuery.agencyName" placeholder="请选择所属机构" />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="padding-left:50px">
              <el-button type="warning" @click="handleFilter('查询')">搜索</el-button>
              <el-button plain class="reset-btn" @click="resetForm">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <!-- 员工排班表格 -->
      <div v-loading="listLoading" :class="{ 'loading-box': listLoading }" element-loading-text="加载中"
           style="margin-top: 20px"
      >
        <el-card shadow="never" class="table-card-box">
          <!-- 新增车辆和绑定排班按钮 -->
          <el-button type="warning" style="margin-bottom:20px" @click="openArrangingSetting">排班设置</el-button>
          <el-button type="warning" plain style="margin-bottom:20px" @click="openScheduleBindingDialog">绑定排班
          </el-button>

          <!-- 员工排班表格 -->
          <el-table
            ref="multipleTable"
            :data="list"
            fit
            style="width: 100%"
            stripe
            :header-cell-style="{ background: 'rgba(250,252,255,1)' }"
          >

            <!-- 添加复选框列 -->
            <el-table-column type="selection" width="55"></el-table-column>

            <!-- 员工信息列 -->
            <el-table-column label="员工账号" min-width="130" prop="employeeNumber"></el-table-column>
            <el-table-column label="员工姓名" min-width="130" prop="name"></el-table-column>
            <el-table-column label="员工电话" min-width="130" prop="phone"></el-table-column>
            <el-table-column label="员工角色" min-width="130" prop="userType"></el-table-column>
            <el-table-column label="当前工作状态" min-width="130" prop="workPatternName"></el-table-column>

            <!-- 每天的排班情况列 -->
            <el-table-column v-for="day in 31" :key="day" :label="day.toString()" min-width="40">
              <template slot-scope="scope">
                <span v-if="scope.row.workSchedules[day - 1]" class="work">上</span>
                <span v-else class="rest">休</span>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </div>
    </div>
    <ScheduleBindingDialog ref="scheduleBindingDialog" />
  </div>
</template>

<script>
import { getWorkScheduling } from '@/api/vehicle'
import ScheduleBindingDialog from './components/schedule-inding-dialog.vue'

export default {
  components: {
    ScheduleBindingDialog
  },
  data() {
    return {
      listLoading: false,
      list: [], // 员工排班数据
      listQuery: {
        userId: '',
        name: '',
        workPatternName: '',
        month: '',
        agencyName: '',
        page: 2,
        pageSize: 10
      }
    }
  },
  mounted() {
    this.handleFilter('查询')
  },
  methods: {
    // 绑定排班按钮点击事件处理程序
    openScheduleBindingDialog() {
      // 获取选中的员工数据
      const selectedRows = this.$refs.multipleTable.selection.map(m => m.id)
      if (selectedRows.length === 0) {
        this.$message.warning('请先选择要绑定排班的员工')
        return
      }

      // 将选中的员工数据传递给绑定排班对话框组件
      this.$refs.scheduleBindingDialog.openDialog(selectedRows)
    },
    openArrangingSetting() {
      this.$router.push({
        path: '/transit/workArrange-setting'
      })
    },
    // 处理搜索和重置
    handleFilter(action) {
      if (action === '查询') {
        this.listQuery.page = 2
        this.getList(this.listQuery)
      } else {
        this.resetForm()
      }
    },
    resetForm() {
      // 清空搜索条件
      this.listQuery = {
        userId: '',
        name: '',
        workPatternName: '',
        month: '',
        agencyName: '',
        page: 2,
        pageSize: 10
      }
      this.getList()
    },
    // 获取员工排班数据
    getList() {
      this.listLoading = true
      getWorkScheduling(this.listQuery)
        .then(res => {
          this.list = res.data.items
          this.listLoading = false
        })
        .catch(e => {
          this.$message({
            message: `操作失败,原因是${e.message}}`,
            type: 'warning'
          })
          this.listLoading = false
        })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep th.date {
  .cell {
    padding-left: 17px !important;
  }
}

.work {
  width: 24px;
  height: 24px;
  background: #ffeeeb;
  border: 1px solid #e15536;
  border-radius: 50%;
  text-align: center;
  color: #e15536;
  font-size: 13px;
}

.history-name {
  width: auto !important;

  ::v-deep .el-input__inner {
    width: 293px;
  }
}

.workArrange-manage-people-setting {
  ::v-deep .el-dialog__body {
    padding: 30px 50px 10px 50px !important;
  }

  ::v-deep .el-dialog__footer {
    padding-bottom: 40px;
  }
}

.work-type {
  ::v-deep .el-form-item__content {
    margin-left: 40px !important;
  }

  ::v-deep .el-radio:first-child {
    margin-right: 80px !important;
  }

  ::v-deep.el-radio__label {
    font-weight: bold;
    color: #333333;
  }
}

.dialog-footer {
  .el-button {
    width: 89px;
    height: 36px;
    padding: 10px 20px;
  }
}

.rest {
  width: 24px;
  height: 24px;
  background: #eff3f8;
  border: 1px solid #d8dde3;
  border-radius: 50%;
  text-align: center;
  color: #20232a;
  font-size: 13px;
}

.alert {
  margin: 10px 0px;
}

.pagination {
  margin-top: 40px;
}

.transport-task ::v-deep .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}

// 下拉框
::v-deep .el-select {
  width: 100%;
}

/*定义滚动条轨道 内阴影+圆角*/
::v-deep .el-table--scrollable-x .el-table__body-wrapper {
  padding-bottom: 5px;
  margin-bottom: 5px;

  &::-webkit-scrollbar {
    height: 10px;
  }

  /*定义滑块 内阴影+圆角*/
  &::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: rgba(144, 147, 153, 0.3);
  }

  &::-webkit-scrollbar-track-piece {
    margin-right: 3px;
    margin-left: 3px;
  }
}

::v-deep .el-card {
  overflow: initial;
}
</style>

<style></style>
